package agents.effect;

import extra.Position;

import constants.*;
import interfaces.ActionInterface;
import interfaces.impl.Effect;

import java.awt.Graphics;
import java.util.ArrayList;

import actions.ActionTeleport;

import objects.WorldObject;
import universe.Universe;

public class EffectMoveRandom extends Effect{
	
	private ActionTeleport actionTeleport;
	private double life=0;
	private double contTime=0;
	
	public EffectMoveRandom(){
		this.id=Constants.AGENT_EFFECT_MOVE_RANDOM;
		
		listActions = new ArrayList<ActionInterface>();
		
		actionTeleport=new ActionTeleport(priority);
		listActions.add(actionTeleport);
		
		timeToAct=1000; ///1 second
		lifeTime=5000;// 5 seconds
		
	}

	@Override
	public void update(WorldObject object, Universe worldI, double time) {
		life = life +time;
		if(life>lifeTime){
			object.addAgentToRemove(this);
			return;
		}
		if(!canUpdate(object)){
			System.out.println("Me falta alguna accion para poder actuar");
			return;
		}
		contTime=contTime+time;
		if(contTime>=timeToAct){
			contTime=0;
			
			double x=((Math.random()*1000)%200)-100 + object.getPosition().getX();
			double y= ((Math.random()*1000)%200)-100 + object.getPosition().getY();
			
			actionTeleport.setPosition(new Position(x,y));
			actionTeleport.setTarget(object);
			actionTeleport.setSource(object);
			object.setImmediatlyActionToDo(actionTeleport);
		}
		
		
	}

	@Override
	public void paint(Graphics g, WorldObject object) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public String getName() {
		// TODO Auto-generated method stub
		return "Effect Move Random";
	}

	
	
}
